/*
This file is part of La Linea.

La Linea is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

La Linea is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with La Linea.  If not, see <http://www.gnu.org/licenses/>.
*/

#pragma once
#ifndef FRAMESTENCIL_H
#define FRAMESTENCIL_H

#include "globals.h"

#include "StencilCurve.h"

#include <deque>
#include <vector>

// This is a set of curves describing a polygon
class FrameStencil
{
	
public:
	static FrameStencil* _currentTess; // Track current tesselation
	std::vector<GLdouble *> _tempVertex; // Used to delete vertex created during tesselation

private:
	std::deque<StencilCurve*> _curves; // Curves constituting the stencil
	int _displayList;

public:
	FrameStencil(void);
	~FrameStencil(void);
	
	// Get curves list
	std::deque<StencilCurve*>& getCurves();
	
	// Add a curve
	void addCurve(StencilCurve* c);

	// Tessellate the contour of this stencil
	void tesselateContour();
	
	// Return the display list
	int getDisplayList();
	
	// Invalidate the display list
	void invalidate();

	// Glu callbacks
	static void CALLBACK stencilTessBegin(GLenum drawMode);
	static void CALLBACK stencilTessEnd();
	static void CALLBACK stencilTessVertex(const GLvoid *data);
	static void CALLBACK stencilTessError(GLenum errorCode);
	static void CALLBACK stencilTessCombine(GLdouble coords[3], GLdouble *vertex_data[4], GLfloat weight[4], GLdouble **dataOut);
};
#endif
